package com.jifeng.br.pjj.bookreader.controller.admin;


import com.jifeng.br.pjj.bookreader.entity.NoticeEntity;
import com.jifeng.br.pjj.bookreader.service.NoticeService;
import com.jifeng.br.pjj.bookreader.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 系统公告表 前端控制器
 * </p>
 *
 * @author 机蜂
 * @since 2023-07-11
 */
@RestController
@RequestMapping("/notice")
public class NoticeController extends BaseController {

    @Autowired
    private NoticeService noticeService;

    @PostMapping("/update")
    public R update(@RequestBody NoticeEntity notice) {
        noticeService.saveOrUpdate(notice);
        return R.ok();
    }

    @GetMapping("/page")
    public R page(int page, int limit, NoticeEntity notice) {
        return R.data(noticeService.getPage(page, limit, notice));
    }

    @GetMapping("/info/{noticeId}")
    public R info(@PathVariable Integer noticeId) {
        return R.data(noticeService.getById(noticeId));
    }

    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable Integer id) {
        noticeService.removeById(id);
        return R.ok();
    }
}

